package com.ncu.music_notification;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

public class MusicServer extends Service {

    private MediaPlayer mediaPlayer;
    public MusicServer() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        //throw new UnsupportedOperationException("Not yet implemented");
        return null;
    }

    @Override
    public void onCreate(){
        super.onCreate();
        this.mediaPlayer = MediaPlayer.create(this,R.drawable.icon);
        this.mediaPlayer.start();
    }

    @Override
    public int onStartCommand(Intent intent,int flag,int startId){
        if(intent.getAction()!=null&&intent.getAction().equals("STOP")){
            stopSelf();
        }
        return  START_STICKY;
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        this.mediaPlayer.stop();
    }
}
